# -*- coding: utf-8 -*-
from django.conf import settings
import logging
import uuid
from datetime import datetime
from common.utils.maestro_exceptions import ExceptionType
from async.task import send_error_message_to_group

_LOGGER = logging.getLogger(__name__)


class TGHandler(logging.Handler):
    def emit(self, record):
        message = self.format(record)
        if 'log.py->log_response' in message:
            return
        if ExceptionType.TG_ALARM.value in message:
            uid = uuid.uuid1()
            time = datetime.now()
            error_info = '{}-{}\n{}'.format(uid, time, message)
            send_error_message_to_group.delay(error_info)
        return
